package com.bastenyang.missyou.api.v1;

import com.bastenyang.missyou.dto.PersonDTO;
import com.bastenyang.missyou.exception.http.ForbiddenException;
import com.bastenyang.missyou.exception.http.NotFundException;
import com.bastenyang.missyou.model.Banner;
import com.bastenyang.missyou.service.BannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/banner")
public class BannerController {

    @Autowired
    private BannerService bannerService;

    @GetMapping("/test")
    public String test(@RequestBody @Validated PersonDTO personDTO){
        String d = personDTO.getPassword1();
        String d2 = personDTO.getPassword2();
        throw new ForbiddenException(10000);
    }

    @GetMapping("/name/{name}")
    public Banner getByName(@PathVariable String name){
        Banner banner = bannerService.getByName(name);
        if(banner == null){
            throw new NotFundException(30005);
        }
        return banner;
    }
}
